package com.dream.system.action;

import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.dream.common.SuperController;
import com.dream.model.SysUser;
import com.dream.system.service.Weixin_ClassService;

@Controller
@RequestMapping("/edu/weiXinClassAction.do")
@SuppressWarnings("all")
public class WeiXinClassAction extends SuperController {

	
	@Autowired
	private Weixin_ClassService weixin_ClassServiceImpl;
	/**
	 * 
	 * 导入excl
	 * 
	 * 
	 * 
	 * @param model
	 * 
	 * @param response
	 * 
	 * @param request
	 * 
	 * @throws IOException
	 */
	@RequestMapping(params = "method=addWeixinClass")
	public void addWeixinClass(SysUser model, @RequestParam("File1") MultipartFile file, HttpServletResponse resp, HttpServletRequest req) throws IOException {
		
		String fileName = file.getOriginalFilename();
		Workbook workbook = null;
		try {
			if (fileName.endsWith(".xls")) {
				workbook = new HSSFWorkbook(file.getInputStream());
			} else if (fileName.endsWith(".xlsx")) {
				workbook = new XSSFWorkbook(file.getInputStream());
			}
			Sheet sheet = workbook.getSheetAt(0);
			int rows = sheet.getLastRowNum();

			for (int i = 0; i < rows; i++) {
				String schoolName =sheet.getRow(i).getCell(0).toString();
				this.weixin_ClassServiceImpl.addschooleName(schoolName);
			} 
		} catch (IOException e) {

		} finally {
			
		}
	}
	
}
